package com.zjl.mapper;

import com.zjl.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * @ClassName EmpMapper
 * @Description TODO
 * @Author ZJL
 * @Date 2023/10/26 18:21
 * @Version 1.0
 **/
@Mapper
public interface EmpMapper {

    //条件查询
    public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);

    //批量删除
    Integer delete(List<Integer> ids);

    //新增
    @Insert("insert into emp(username,name,gender,image,job,entrydate,dept_id,create_time,update_time)" +
            " values(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    Integer insert(Emp emp);

    @Select("select * from emp where id = #{id}")
    Emp findById(Integer id);

    Integer update(Emp emp);

    /**
     * 根据用户名和密码查询员工
     * @param emp
     * @return
     */
    @Select("select * from emp where username=#{username} and password =#{password}")
    Emp getByUsernameAndPassword(Emp emp);

    //根据部门id删除部门下所有员工
    @Delete("delete from emp where dept_id=#{deptId}")
    public int deleteByDeptId(Integer deptId);

}
